/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("deviceinfo",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.RadarDevice.IServices;
using Microsoft.AspNetCore.Authorization;
using VOL.Entity.DomainModels.Devices.Dto;
using System.IO;
using SharpCompress.Common;
using VOL.Core.Utilities;

namespace VOL.RadarDevice.Controllers
{
    public partial class deviceinfoController
    {
        private readonly IdeviceinfoService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public deviceinfoController(
            IdeviceinfoService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// 上传升级文件进行设备升级
        /// </summary>
        /// <param name="formData">附加参数</param>
        /// <returns></returns>
        [HttpPost, Route("uploadFile"), AllowAnonymous]
        public WebResponseContent UploadFile(IFormCollection formData)
        {
            if (!Request.HasFormContentType)
            {
                
                WebResponseContent webResponse = new WebResponseContent();
                return new WebResponseContent().Error("参数错误");
            }
            var files = Request.Form.Files;

            if (files == null || files.Count == 0)
            {
                return new WebResponseContent().Error("请选择文件！");
            }
            var file = files[0]; // 假设只上传了一个文件
            return _service.UploadFile(formData, file);
        }
        /// <summary>
        /// 取消升级
        /// </summary>
        /// <param name="deviceNo">设备号</param>
        /// <returns></returns>
        [HttpPost, HttpGet,Route("cancelUpgrade"), AllowAnonymous]
        public async Task<IActionResult> CancelUpgrade(string deviceNo)
        {
            return Json(await Service.CancelUpgrade(deviceNo));
        }
    }
}
